package com.lzj.demo.design.memo;

import cn.hutool.json.JSONUtil;
import lombok.extern.slf4j.Slf4j;

import java.util.Date;

@Slf4j
public class Test {
    public static void main(String[] args) {
        Admin admin = new Admin();
        ConfigOriginator originator = new ConfigOriginator();
        originator.setConfigFile(new ConfigFile("1001","配置内容A=AA",new Date(),"Faker"));
        admin.append(originator.saveMemo());
        originator.setConfigFile(new ConfigFile("1002","配置内容B=BB",new Date(),"Suzy"));
        admin.append(originator.saveMemo());
        originator.setConfigFile(new ConfigFile("1003","配置内容C=CC",new Date(),"Fly"));
        admin.append(originator.saveMemo());
        originator.setConfigFile(new ConfigFile("1004","配置内容D=DD",new Date(),"Faker"));
        admin.append(originator.saveMemo());

        originator.getMemo(admin.undo());
        log.info("历史配置回滚:{}", JSONUtil.toJsonStr(originator.getConfigFile()));

        originator.getMemo(admin.undo());
        log.info("历史配置回滚:{}", JSONUtil.toJsonStr(originator.getConfigFile()));

        originator.getMemo(admin.redo());
        log.info("历史配置前进:{}", JSONUtil.toJsonStr(originator.getConfigFile()));

        originator.getMemo(admin.get("1002"));
        log.info("历史配置获取:{}", JSONUtil.toJsonStr(originator.getConfigFile()));
    }
}
